<template>
  <body>
    <input type="button" onclick="get()" value="点击以显示天气" />
  </body>
</template>

<script type="text/javascript">
function get() {
  var URL = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx";
  var city = "重庆";
  var data = '<?xml version=1.0> encoding="UTF-8"?>';
  data =
    data +
    '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
  data = data + "<soap:Body>";
  data = data + '<getWeatherbyCityName xmlns="http://WebXml.com.cn/">';
  data = data + "<theCityName>" + city + "</theCityName>";
  data = data + "</getWeatherbyCityName>";
  data = data + "</soap:Body>";
  data = data + "</soap:Envelope>";
  if (window.ActiveXObject) {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } else if (window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest();
  }
  xmlhttp.open("POST", URL, false);
  xmlhttp.setRequestHeader("CONTENT-TYPE", "text/xml;charset=UTF-8");
  xmlhttp.setRequestHeader(
    "SOAPAction",
    "http://WebXml.com.cn/getWeatherbyCityName"
  );
  xmlhttp.send(data);
  var xmlDoc = xmlhttp.responseXML;
  var weather = new Array(23);
  for (i = 0; i < 23; i++)
    weather[i] = xmlDoc.documentElement
      .childNodes(0)
      .childNodes(0)
      .childNodes(0)
      .childNodes(i).text;
  alert(weather);
}
</script>

<style scoped>
</style>